package com.example.arithmeticleetcode.learnArithmetic2.union;

import com.example.arithmeticleetcode.learnArithmetic2.sort.utils.Times;
import com.example.arithmeticleetcode.learnArithmetic2.union.bo.Student;

import java.util.Arrays;

/**
 * @program: arithmetic-leetcode
 * @description:
 * @author: FangZhen
 * @create: 2020-11-12 13:49
 **/
public class Main {

    static int count = 100_0000;

    public static void main(String[] args) {
//        test(new UnionFind_QF(12));
//        test(new UnionFind_QU(12));
//        test(new UnionFind_QU_S(12));
//        test(new UnionFind_QU_R(12));
//        test(new UnionFind_QU_R_PC(12));
//        test(new UnionFind_QU_R_PS(12));
//        test(new UnionFind_QU_R_PH(12));

//        System.out.println("=====================");

//        testTime(new UnionFind_QF(count));
//        testTime(new UnionFind_QU(count));
//        testTime(new UnionFind_QU_S(count));
//        testTime(new UnionFind_QU_R(count));
        testTime(new UnionFind_QU_R_PC(count));
        testTime(new UnionFind_QU_R_PS(count));
        testTime(new UnionFind_QU_R_PH(count));

//        GenericUnionFind<Student> genericUnionFind = new GenericUnionFind<>();
//        Student student1 = new Student(1, "jack");
//        Student student2 = new Student(2, "rose");
//        Student student3 = new Student(3, "jack");
//        Student student4 = new Student(4, "rose");
//
//        genericUnionFind.makeSet(student1);
//        genericUnionFind.makeSet(student2);
//        genericUnionFind.makeSet(student3);
//        genericUnionFind.makeSet(student4);
//        System.out.println(genericUnionFind.find(student1));
//        System.out.println(genericUnionFind.find(student2));
//        System.out.println(genericUnionFind.find(student3));
//        System.out.println(genericUnionFind.find(student4));
//        System.out.println("=========================");
//        genericUnionFind.union(student1, student2);
//        genericUnionFind.union(student3, student4);
//        System.out.println(genericUnionFind.find(student1));
//        System.out.println(genericUnionFind.find(student2));
//        System.out.println(genericUnionFind.find(student3));
//        System.out.println(genericUnionFind.find(student4));
//        System.out.println(genericUnionFind.isSanme(student1, student2));
//        System.out.println(genericUnionFind.isSanme(student3, student4));
//        System.out.println(genericUnionFind.isSanme(student1, student3));
//        genericUnionFind.union(student1, student3);
//        System.out.println(genericUnionFind.isSanme(student1, student3));

        test(new GenericUnionFind<Integer>());
    }

    static void test(GenericUnionFind<Integer> unionFind) {
        for (int i = 0; i < count; i++) {
            unionFind.makeSet(i);
        }
//        unionFind.union(0, 1);
//        unionFind.union(0, 3);
//        unionFind.union(0, 4);
//        unionFind.union(2, 3);
//        unionFind.union(2, 5);
//
//
//        unionFind.union(6, 7);
//
//        unionFind.union(8, 10);
//        unionFind.union(9, 10);
//        unionFind.union(9, 11);
//        System.out.println(unionFind.isSame(2, 7));
//        unionFind.union(4, 6);
//        System.out.println(unionFind.isSame(2, 7));

        Times.test(unionFind.getClass().getSimpleName(), () -> {
            for (int i = 0; i < count; i++) {
                unionFind.union((int) (Math.random() * count), (int) (Math.random() * count));
            }

            for (int i = 0; i < count; i++) {
                unionFind.isSame((int) (Math.random() * count), (int) (Math.random() * count));
            }
        });
    }

    static void testTime(UnionFind uf) {
        Times.test(uf.getClass().getSimpleName(), () -> {
            for (int i = 0; i < count; i++) {
                uf.union((int) (Math.random() * count), (int) (Math.random() * count));
            }

            for (int i = 0; i < count; i++) {
                uf.isSame((int) (Math.random() * count), (int) (Math.random() * count));
            }
        });
    }
}
